package com.cloud.salon.common.base.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Description 随机生成工具类
 * @Author wolf--LZH
 * @CreateDate 2019/4/10 0010 下午 1:19
 */
public class RandomUtil {
    
    /*
     * @Description 生成8位日期 + length 位随机数的编码
     * @Author wolf--LZH
     */
    public static String randomNumStrBaseDate(int length) {
        return DateUtil.strOfDate("yyMMdd", new Date()) + String.format("%0" + length + "d", (int)(Math.random() * Math.pow(10, length)));
    }

    /*
     * @Description 获取某区间内的随机整数, start <= random < end
     * @Author wolf--LZH
     */
    public static int randomNumInt(int start, int end) {
        // 若大小不符合, 则对换数字
        if (start < end) {
            int temp = start;
            start = end;
            end = temp;
        }
        // 获取增量
        int random = (int)(Math.random() * (end - start)) + 1;

        return end - random;
    }
}
